home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / Editor / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  8KB  |  305 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   DoorName
  5.   ========
  6.  
  7.     what the door does
  8.  
  9.   Version
  10.   =======
  11.  
  12.     x.xx, release xx, dd/mm/yyyy
  13.  
  14.   Options
  15.   =======
  16.  
  17.     N_ND->ActiveDoor->SystemOptions
  18.     -------------------------------
  19.  
  20.  
  21.  
  22.     Command Line Arguments
  23.     ----------------------
  24.  
  25.     2  <option>
  26.  
  27.     3  ...
  28.  
  29.     4  .
  30.  
  31.   ToDo
  32.   ====
  33.  
  34.     what you still have to do
  35.  
  36.  
  37.  
  38. */
  39.  
  40. /* **** Includes *********************************************************** */
  41.  
  42. #include <exec/types.h>
  43. #include <exec/memory.h>
  44. #include <dos/dos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/dos_protos.h>
  47. #include <clib/alib_protos.h>
  48.  
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <stdio.h>
  52. #include <ctype.h>
  53. #include <time.h>
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/types.h>
  58. #include <HBBS/structures.h>
  59. #include <HBBS/hbbscommon_protos.h>
  60. #include <HBBS/hbbscommon_pragmas.h>
  61. #include <HBBS/Hbbsnode_protos.h>
  62. #include <HBBS/Hbbsnode_pragmas.h>
  63. #include <HBBS/release.h>
  64. char *versionstr="$VER: Editor "RELEASE_STR;
  65.  
  66. /* **** Variables ********************************************************** */
  67.  
  68.  
  69. struct Library *HBBSCommonBase  = NULL;
  70. struct Library *HBBSNodeBase    = NULL;
  71.  
  72. struct BBSGlobalData *BBSGlobal = NULL;
  73. struct NodeData *N_ND           = NULL;
  74. int    N_NodeNum                = -1;
  75. char   outstr[1024];
  76.  
  77. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  78.                       // random/suprious crashings after or during the running
  79.                       // of your door.
  80.  
  81. int    gargc;         // these are just copies of main()'s argc and argv..
  82. char   **gargv;
  83.  
  84. /* **** Functions ********************************************************** */
  85.  
  86.  
  87. #ifdef __SASC
  88. int CXBRK(void) { return(0); }
  89. int _CXBRK(void) { return(0); }
  90. void chkabort(void) {}
  91. #endif
  92.  
  93. static VOID cleanup(ULONG num)
  94. {
  95.   if (HBBSNodeBase)
  96.   {
  97.     HBBS_CleanUpDoor();
  98.     CloseLibrary (HBBSNodeBase);
  99.   }
  100.  
  101.   if (HBBSCommonBase)
  102.   {
  103.     HBBS_CleanUpCommon();
  104.     CloseLibrary (HBBSCommonBase);
  105.   }
  106.  
  107.   if (num) printf("Door Error = %d\n",num);
  108.  
  109.   exit(0);
  110. }
  111.  
  112. static VOID init(char *name)
  113. {
  114.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  115.   {
  116.     cleanup(1);
  117.   }
  118.  
  119.   if (!(HBBS_InitCommon()))
  120.   {
  121.     cleanup(2);
  122.   }
  123.  
  124.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  125.   {
  126.     cleanup(3);
  127.   }
  128.  
  129.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  130.   {
  131.     cleanup(4);
  132.   }
  133.   SetProgramName(name);
  134. }
  135.  
  136. /* **** DoorMain *********************************************************** */
  137.  
  138. void DoorMain( void )
  139. {
  140.   V_BIGNUM LineNum=0,loop;
  141.   BOOL Done=FALSE;
  142.   BOOL Save=FALSE;
  143.   struct List *TextList;
  144.   char linewrap[BIG_STR]="";
  145.   struct Node *node;
  146.  
  147.   // if load specified then load filename specified in paramstr[2]
  148.   if (!((stricmp(gargv[3],"LOAD")==0) && (TextList=HBBS_LoadFile(gargv[2]))))
  149.   {
  150.     TextList=HBBS_CreateList();
  151.   }
  152.  
  153.   LineNum=HBBS_NodesInList(TextList);
  154.  
  155.   if (TextList)
  156.   {
  157.     DOOR_WriteText("-- Enter Lines Of Text Below, blank line to bring up menu --------------\r\n");
  158.  
  159.     do
  160.     {
  161.       sprintf(outstr,"%02d) ",LineNum+1);
  162.       DOOR_WriteText(outstr);
  163.  
  164.       DOOR_GetLine(GL_HISTORY|GL_EDIT|GL_DISPLAY|GL_LINEWRAP|GL_IMMEDIATE,'\0',75,0,linewrap);
  165.       strcpy(linewrap,N_ND->CurrentLineWrap);
  166.       if (N_ND->OnlineStatus==OS_ONLINE)
  167.       {
  168.         if (N_ND->CurrentLine[0]==0)
  169.         {
  170.           // pop up a menu HERE.
  171.           strcpy(N_ND->CharsAllowed,"WwDdSsLlEeCcQq");
  172.           DOOR_MenuPrompt("[S]ave, [D]elete, [L]ist, [E]dit, [C]ontinue, [Q]uit >",'C');
  173.           DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS|GL_IMMEDIATE,'\0',1,0,NULL);
  174.           if (N_ND->OnlineStatus==OS_ONLINE)
  175.           {
  176.             if (N_ND->CurrentLine[0])
  177.             {
  178.               switch (toupper(N_ND->CurrentLine[0]))
  179.               {
  180.                 case 'W': // *C* make user aware of this key!
  181.                   DOOR_WriteText(ANSI_CLS);
  182.                   break;
  183.                 case 'S':
  184.                   Done=TRUE;
  185.                   Save=TRUE;
  186.                   break;
  187.                 case 'Q':
  188.                   if (DOOR_ContinuePrompt("Are you sure you want to abort this text ? ",DEFAULT_NO|DCP_ADDYN))
  189.                   {
  190.                     Done=TRUE;
  191.                     DOOR_Return("CANCEL");
  192.                   }
  193.                   break;
  194.                 case 'C':
  195.                   break;
  196.                 case 'D':
  197.                   DOOR_WriteText("Enter Line Number > ");
  198.                   strcpy(N_ND->CharsAllowed,"0123456789");
  199.                   DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS,'\0',3,0,NULL);
  200.                   if (N_ND->OnlineStatus==OS_ONLINE)
  201.                   {
  202.                     if (sscanf(N_ND->CurrentLine,"%d",&loop))
  203.                     {
  204.                       if (loop>0 && loop<=LineNum)
  205.                       {
  206.                         node=GetNode(TextList,loop-1);
  207.                         Remove(node);
  208.                         FreeStr(node->ln_Name);
  209.                         FreeVec(node);
  210.                         LineNum--;
  211.  
  212.                       }
  213.                     }
  214.                   }
  215.                   break;
  216.                 case 'E':
  217.                   DOOR_WriteText("Enter Line Number > ");
  218.                   strcpy(N_ND->CharsAllowed,"0123456789");
  219.                   DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS,'\0',3,0,NULL);
  220.                   if (N_ND->OnlineStatus==OS_ONLINE)
  221.                   {
  222.                     if (sscanf(N_ND->CurrentLine,"%d",&loop))
  223.                     {
  224.                       if (loop>0 && loop<=LineNum)
  225.                       {
  226.                         node=GetNode(TextList,loop-1);
  227.                         sprintf(outstr,"%02d) ",loop);
  228.                         DOOR_WriteText(outstr);
  229.                         DOOR_GetLine(GL_HISTORY|GL_EDIT|GL_DISPLAY,'\0',75,0,node->ln_Name);
  230.                         if (N_ND->OnlineStatus==OS_ONLINE)
  231.                         {
  232.                           if (N_ND->CurrentLine[0])
  233.                           {
  234.                             if (!FreeAndSet(&node->ln_Name,N_ND->CurrentLine))
  235.                             {
  236.                               Remove(node);
  237.                               FreeVec(node);
  238.                               LineNum--;
  239.                             }
  240.                           }
  241.                         }
  242.                       }
  243.                     }
  244.                   }
  245.                   break;
  246.                 case 'L':
  247.                   for (loop=0,node=TextList->lh_Head;node->ln_Succ;node=node->ln_Succ,loop++)
  248.                   {
  249.                     sprintf(outstr,"%02d) %s\r\n",loop+1,node->ln_Name);
  250.                     DOOR_WriteText(outstr);
  251.                   }
  252.                   break;
  253.                 default:
  254.                   DOOR_WriteText("Unknown Option!\r\n");
  255.                   break;
  256.               }
  257.             }
  258.           } else Done=TRUE; //lost carrier!
  259.         }
  260.         else
  261.         {
  262.           LineNum++;
  263.           NewStrNode(N_ND->CurrentLine,TextList);
  264.         }
  265.       }
  266.     } while (!Done && N_ND->OnlineStatus==OS_ONLINE);
  267.     if (Save)
  268.     {
  269.       if (LineNum)
  270.       {
  271.         HBBS_SaveFile(gargv[2],TextList);
  272.       }
  273.       else
  274.       {
  275.         DOOR_WriteText("Message Containes No Text, Cancelled!\r\n");
  276.         DOOR_Return("CANCEL");
  277.       }
  278.     }
  279.   }
  280. }
  281.  
  282. int main(int argc,char **argv)
  283. {
  284.   gargc=argc;
  285.   gargv=argv;
  286.  
  287.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  288.   {
  289.     printf("Invalid/No Paramaters for door!\n");
  290.     exit (20);
  291.   }
  292.   init("Editor");
  293.  
  294.   if (BBSGlobal=HBBS_GimmeBBS())
  295.   {
  296.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  297.     {
  298.       DoorMain();
  299.     }
  300.   }
  301.   cleanup(0);
  302. }
  303.  
  304. /* **** End Of File ******************************************************** */
  305.